#if !defined GRAYSCALER
#define GRAYSCALER

#include "cv.h"


class GrayScaler {

private:

	// private attributes
	IplImage *output;

public:

	// empty constructor
	GrayScaler() : output(0) { 

		// default parameter initialization here
	}

	// getters and setters
	

	IplImage* getOutputImage() {

		return output;
	}

	// to check if an initialization is required
	bool isInitialized(IplImage *image) {

		return output && (output->width == image->width) 
			&& (output->height == image->height);
	}

	// for all memory allocation
	void initialize(IplImage *image) {

		cvReleaseImage(&output);
		output= cvCreateImage(cvSize(image->width,image->height),
			8, 1);
	}

	// the processing of the image
	void process(IplImage *image);
	void processOpenMP(IplImage *image);

	// the method that checks for initilization
	// and then process the image
	inline void processImage(IplImage *image) {

		if (!isInitialized(image)) {

			initialize(image);
		}

		process(image);
	}
	inline void processImageOpenMP(IplImage *image) {

		if (!isInitialized(image)) {

			initialize(image);
		}

		processOpenMP(image);
	}
	// memory de-allocation
	void release() {

		cvReleaseImage(&output);
	}

	~GrayScaler() {

		release();
	}
};

#endif
